<script>
export default {
  name: 'TodoMain',
}
</script>
<script setup name="TodoMain">
import { storeToRefs } from 'pinia'
import useStore from '../../store'
const { todos } = useStore()
const { renderList } = storeToRefs(todos)
</script>
<template>
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox" :checked="todos.isCheckAll" @change="todos.checkAll(!todos.isCheckAll)" />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li
        :class="{
          // 当值为 true 用左边的 key 当做 class
          completed: item.done,
        }"
        v-for="item in renderList"
        :key="item.id"
      >
        <div class="view">
          <!-- 这儿可以双向绑定 -->
          <!-- <input class="toggle" type="checkbox" v-model="item.done" /> -->
          <!-- 也可以监听 input 的 onchange，在 onchange 回调中调用 actions 中方法修改对应的那一条数据的 done -->
          <input class="toggle" type="checkbox" :checked="item.done" @change="todos.changeDone(item.id)" />
          <label>{{ item.name }}</label>
          <button class="destroy" @click="todos.delTodo(item.id)"></button>
        </div>
        <input class="edit" value="Create a TodoMVC template" />
      </li>
    </ul>
  </section>
</template>
